package com.kangyi.app.controller;

import com.kangyi.app.service.BookService;
import com.kangyi.dto.AddNursingHomeBooking;
import com.kangyi.result.Result;
import com.kangyi.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/app/book")
@Slf4j
@Api(tags = "预约相关接口")
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping("/appointment")
    @ApiOperation("预约养老院")
    @CacheEvict(cacheNames = "NursingHomeBooking_",allEntries = true)
    public Result addNursingHomeBooking(@RequestBody AddNursingHomeBooking addNursingHomeBooking){
        log.info("预约养老院：{}",addNursingHomeBooking);
        try {
            AuthUtil.validateUserPermission(addNursingHomeBooking.getUserId());
            bookService.addNursingHomeBooking(addNursingHomeBooking);
            return Result.success("预约成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
